package com.jinken.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.jinken.common.R;
import com.jinken.request.LoginRequest;
import com.jinken.service.IUserService;
import com.jinken.utils.JwtUtils;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {
    @Override
    public R login(LoginRequest request) {
        // 1、用户名或者密码校验
        if (StringUtils.isEmpty(request.getUsername()) || StringUtils.isEmpty(request.getPassword()) ){
            return R.error("用户名或者密码为空");
        }
        //模拟持久层数据查询
        if("admin".equals(request.getUsername()) && "123456".equals(request.getPassword())){
            //生成令牌
            String token = JwtUtils.sign(100L, "admin");
            return R.success(token);
        }
        return R.error("账号密码错误，请重新登录");
    }
}
